package com.biao.hashmap;

import java.util.ArrayList;
import java.util.List;

public class Demo03_ArrayList_HashMap<K, V> {
    private List<Entry<K, V>> entrys = new ArrayList<>();

    class Entry<K, V> {
        K k;
        V v;

        public Entry(K k, V v) {
            this.k = k;
            this.v = v;
        }
    }

    public void put(K k, V v) {
        entrys.add(new Entry<K, V>(k, v));
    }

    public V get(K k) {
        for (Entry<K, V> entry : entrys) {
            if (entry.k.equals(k)) {
                return entry.v;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        Demo03_ArrayList_HashMap<Object, Object> map = new Demo03_ArrayList_HashMap<>();
        map.put("a", "a");
        map.put(97, "97");
        System.out.println(map.get("a"));
        System.out.println(map.get(97));
        // 此效率极差，链表从头查到尾，O(n)

    }
}
